package com.alex.utils.textsearch.filter;

import com.alex.utils.textsearch.SentenceFilter;

public class PairParenthesesFilter implements SentenceFilter {

	@Override
	public boolean filter(String sentence) {
		int left = 0;
		int right = 0;
		int quotes = 0;
		for (int i = 0; i < sentence.length(); i++) {
			char ch = sentence.charAt(i);
			if (ch == '(') {
				left++;
			} else if (ch == ')'){
				right++;
			} else if (ch == '\"') {
				quotes++;
			}
		}
		return left == right && quotes % 2 == 0;
	}

}
